home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / das / passa.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  2KB  |  100 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6.  
  7. /*
  8.  *  PASSA
  9.  *
  10.  *  Scan and resolve all label types & opcodes. fields:
  11.  *    Label
  12.  *    OpCode
  13.  *    OpSize    (0 == unspecified)
  14.  *
  15.  *  Creates appropriate MachCtx structures
  16.  */
  17.  
  18. #include "defs.h"
  19.  
  20. Prototype void    PassA(void);
  21.  
  22. void
  23. PassA()
  24. {
  25.     char *ptr = AsBuf;
  26.     char c;
  27.     MachCtx *mc;
  28.     long lineno = 0;
  29.  
  30.     while ((c = *ptr) != 0) {
  31.     LineNo = ++lineno;
  32.     if (c == '\n') {
  33.         ++ptr;
  34.         continue;
  35.     }
  36.     mc = AllocStructure(MachCtx);
  37.     mc->Sect = CurSection;
  38.     mc->LineNo = lineno;
  39.     MBase[MLines++] = mc;
  40.  
  41.     if (c != ' ' && c != '\t') {      /*  label   */
  42.         char *skip = ptr;
  43.         Label *label;
  44.         while (c != '\n' && c != ' ' && c != '\t' && c != ':')
  45.         c = *++ptr;
  46.         *ptr = 0;
  47.         mc->Label = label = GetLabelByName(skip);
  48.         if (label->Sect && label->Sect->Type != SECT_COMMON) {
  49.         cerror(EERROR_LABEL_MULTIPLY_DEFINED, label->Name);
  50.         } else {
  51.         label->Sect = CurSection;
  52.         label->MC = MBase + MLines - 1;
  53.         }
  54.         if (c == ':')
  55.         c = *++ptr;
  56.  
  57.         /*
  58.         if (++label->l_Cre > 1)
  59.         xxxcerror(EERROR, "Duplicate label: %s", label->Name);
  60.         */
  61.     }
  62.     while (c == ' ' || c == '\t')
  63.         c = *++ptr;
  64.     if (c != '\n') {         /*  opcode/directive    */
  65.         char *skip = ptr;
  66.         while (c != '\n' && c != ' ' && c != '\t' && c != '.') {
  67.         if (c >= 'a' && c <= 'z')
  68.             *ptr &= ~0x20;     /*  -> upper case */
  69.         c = *++ptr;
  70.         }
  71.         *ptr = 0;
  72.         mc->OpCode = GetOpByName(skip);
  73.  
  74.         if (c == '.') {
  75.         mc->OpSize = CToSize(*++ptr);
  76.         c = *++ptr;
  77.         }
  78.  
  79.  
  80.         if (mc->OpCode == NULL)
  81.         cerror(EERROR_UNKNOWN_DIRECTIVE, skip);
  82.  
  83.         if (c != '\n') {
  84.         while (c == ' ' || c == '\t')
  85.             c = *++ptr;
  86.         mc->m_Operands = ptr;
  87.         } else {
  88.         mc->m_Operands = "";
  89.         }
  90.         while (c != '\n')
  91.         c = *++ptr;
  92.     }
  93.     *ptr++ = 0;
  94.     if (mc->OpCode && mc->OpCode->Id < 0)
  95.         ExecOpCodeA(mc);
  96.     }
  97.     MBase[MLines] = NULL;
  98. }
  99.  
  100.